if(!dojo._hasResource["opm.widgets.GenericStack"]){
dojo._hasResource["opm.widgets.GenericStack"] = true;
dojo.provide("opm.widgets.GenericStack");
dojo.require("dijit._Widget");;
dojo.declare("opm.widgets.GenericStack",dijit._Widget,
{
   contentId:"",
   data:[],
   _currentItemSelected:0,
   hasDisabledStackInactiveYet:true,
   constructor:function(args){
      this.setAtts(args);
   },
   setAtts:function(args){
     this.contentId = args.contentId;
     this.data = args.data;
     this.hasDisabledStackInactiveYet = args.hasDisabledStackInactiveYet;
   },
   connectEvent:function(eventName, callBackFunction){
      if (eventName == 'selectedItem'){
         this._selectedItem = callBackFunction;
      }
   },
   generic:function(){
      dojo.byId(this.contentId).innerHTML = this._layout();
      this._initArrow();
   },
   gotoNextItem:function () {
     var itemObject = dojo.query("#stack_"+this._currentItemSelected);
     itemObject.removeClass("childMenuStackActive");
     itemObject.addClass("childMenuStackComplete");
     this._currentItemSelected = this._currentItemSelected + 1;
     var newItem = dojo.query("#stack_"+this._currentItemSelected);
     newItem.removeClass("childMenuStackInActive"); 
     newItem.addClass("childMenuStackActive");
     newItem.removeAttr("disabled");
     this._selectedItem(this.getItem(this._currentItemSelected));
   },
   getItem:function(index){return this.data[index]},
   _selectedItem:function(){},
   setIndexItem:function(index){this._currentItemSelected=index;},
   _initArrow:function(){
      var stackObject = this;
      for (var index=0; index<this.data.length; index++){
          dojo.query("#stack_"+index).onclick(function(){
             var itemId = this.id;
             var result = dojo.getNodeProp(itemId, "disabled");
             if (result != "true"){
                 var itemIndex = itemId.split("_")[1];
                 stackObject._selectedItem(stackObject.getItem(itemIndex));
                 stackObject.setIndexItem(Number(itemIndex));
             }
          })
      }
      this._selectedItem(this.getItem(this._currentItemSelected));
   },
   _layout : function(){
      var html = '<ul class="menuStack">';
      for (var index=0; index<this.data.length; index++){
        var object = this.data[index];
        if (index == 0)
            html += '<li><a class="childMenuStackActive" href="#" id="stack_'+index+'">'+object.title+'</a></li>';
        else if (this.hasDisabledStackInactiveYet == true){
            html += '<li><a class="childMenuStackInActive" href="#" disabled="true" id="stack_'+index+'">'+object.title+'</a></li>';
        } else {
            html += '<li><a class="childMenuStackActive" href="#" id="stack_'+index+'">'+object.title+'</a></li>';
        }
      }
      html += '</ul>';
      return html;
   }
}
);
}